package myATMCaseV1;

import java.math.BigDecimal;

public class AccountControl {
    AccountBLL accountBLL = new AccountBLL();
    Account myAccount;

    //登陆账户
    public boolean login(Integer uid, String password){
        Account returnAccount = accountBLL.getAccount(uid, password);
        if(returnAccount == null){
            return false;
        }
        this.myAccount = returnAccount;
        return true;
    }

    //查询业务（通过uid）
    public Account queryAccount(Integer uid){
        if(uid == myAccount.getUid()){
            return null;
        }
        Account returnAccount = accountBLL.queryAccount(uid);
        if(returnAccount == null){
            return null;
        }
        return returnAccount;
    }

    //转账业务
    public boolean transfer(Account toAccount, BigDecimal money){
        return accountBLL.transfer(myAccount, toAccount, money);
    }

    //取款业务
    public boolean withdrawal(BigDecimal money){
        return accountBLL.withdrawal(myAccount, money);
    }

    //存款业务
    public boolean deposit(BigDecimal money){
        return accountBLL.deposit(myAccount, money);
    }

    //查询余额
    public BigDecimal checkBalance(){
        return myAccount.getBalance();
    }

    //查询账户信息
    public Account searchInfo(){
        return myAccount;
    }
    //修改账户信息
    public boolean modifyInfoUsername(String username){
        myAccount.setUsername(username);
        return accountBLL.modifyInfo(myAccount);
    }
    public boolean modifyInfoPassword(String password){
        myAccount.setPassword(password);
        return accountBLL.modifyInfo(myAccount);
    }

}
